/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.tags;

import alcatelparser.modules.AlgoUtil;
import alcatelparser.modules.BuilderFactory;
import alcatelparser.modules.Env;
import alcatelparser.modules.I;

/**
 *
 * @author geniuz
 */
public class SupplementaryServicesTag extends DefaultParserTag
{

    public SupplementaryServicesTag()
    {
    }

    public final void parseTag(int ai[], int i)
    {
        _serviceNumber = 1;
        _array = ai;
        _startParsePosition = i;
        _length = AlgoUtil.getLength(ai, i + 1);
        setStandartLength(ai, i);
        /*
        if(isFullForm())
            BuilderFactory.getBuilder().writeTagContent(3, 0, getTagPropertiesValue(I.I(6901)), getTagIdentifyContent(i, i + 1));
        parseSupplementaryService(i);
        parseServices(i);*/
    }

    private void parseServices(int i)
    {
        int j = _length - 4;
        int k = Env.getEnv().getNumberOfSS();
        for(int l = 0; l < j && _serviceNumber <= k; _serviceNumber++)
        {
            int i1 = parseCode(i + 4 + l);
            l += i1;
            i1 = parseAction(i + 4 + l);
            l += i1;
        }

    }

    private int parseAction(int i)
    {
        int j = AlgoUtil.getLength(_array, i + 1);
        int k = _array[i + 2];
        if(isFullForm())
        {
            String s = (new StringBuilder()).append(getTagIdentifyContent(i, i + 1)).append(toHex(k)).append(I.I(5425)).append(getTagPropertiesValue((new StringBuilder()).append(I.I(6773)).append(k).toString())).toString();
            BuilderFactory.getBuilder().writeTagContent(5, 0, getTagPropertiesValue(I.I(6848)), s);
        } else
        if(isTagChecked(I.I(6881)))
        {
            String s1 = isFieldsDecoding() ? getTagPropertiesValue((new StringBuilder()).append(I.I(6773)).append(k).toString()) : toHex(k);
            BuilderFactory.getBuilder().writeTagContent(1, 0, (new StringBuilder()).append(getReducedTagPropertiesValue(I.I(6848))).append(_serviceNumber).toString(), s1);
        }
        return j + 2;
    }

    private int parseCode(int i)
    {
        int j = AlgoUtil.getLength(_array, i + 1) + 2;
        int k = _array[i + 2];
        int l = (k << 8) + _array[i + 3];
        if(isFullForm())
        {
            String s = getTagIdentifyContent(i, i + 1);
            s = (new StringBuilder()).append(s).append(toHex(l)).append(I.I(5425)).append(getTagPropertiesValue((new StringBuilder()).append(I.I(6773)).append(l).toString())).toString();
            BuilderFactory.getBuilder().writeTagContent(5, 0, getTagPropertiesValue(I.I(6792)), s);
        } else
        if(isTagChecked(I.I(6823)))
        {
            String s1 = isFieldsDecoding() ? getTagPropertiesValue((new StringBuilder()).append(I.I(6773)).append(l).toString()) : getHexStringContent(i + 2, j - 2);
            BuilderFactory.getBuilder().writeTagContent(1, 0, (new StringBuilder()).append(getReducedTagPropertiesValue(I.I(6792))).append(_serviceNumber).toString(), s1);
        }
        return j;
    }

    private void parseSupplementaryService(int i)
    {
        if(isFullForm())
            BuilderFactory.getBuilder().writeTagContent(4, 0, getTagPropertiesValue(I.I(6747)), getTagIdentifyContent(i + 2, i + 3));
    }

    public final String getParseIdentityTag()
    {
        return I.I(6744);
    }

    public final int getServiceNumber()
    {
        return _serviceNumber;
    }

    private int _serviceNumber;
    private int _length;
}
